package com.ruoyi.pressure.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pressure.domain.KyLaneMgylHistory;
import com.ruoyi.pressure.service.IKyLaneMgylHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 描 杆（索）应力测点历史信息数据项说明Controller
 * 
 * @author lth
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/pressure/mgylHistory")
public class KyLaneMgylHistoryController extends BaseController
{
    @Autowired
    private IKyLaneMgylHistoryService kyLaneMgylHistoryService;

    /**
     * 查询描 杆（索）应力测点历史信息数据项说明列表
     */
    @PreAuthorize("@ss.hasPermi('pressure:mgylHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(KyLaneMgylHistory kyLaneMgylHistory)
    {
//        startPage();
//        List<KyLaneMgylHistory> list = kyLaneMgylHistoryService.selectKyLaneMgylHistoryList(kyLaneMgylHistory);
//        return getDataTable(list);
        List<KyLaneMgylHistory> list = kyLaneMgylHistoryService.selectKyLaneMgylHistoryList(kyLaneMgylHistory);

        TableDataInfo rspData = new TableDataInfo();
        Integer total = Math.toIntExact(list.size());
        rspData.setCode(200);
        rspData.setTotal(total);
        rspData.setMsg("查询成功");

        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        list = list.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        rspData.setRows(list);

        return rspData;
    }

    /**
     * 导出描 杆（索）应力测点历史信息数据项说明列表
     */
    @PreAuthorize("@ss.hasPermi('pressure:mgylHistory:export')")
    @Log(title = "描 杆（索）应力测点历史信息数据项说明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KyLaneMgylHistory kyLaneMgylHistory)
    {
        List<KyLaneMgylHistory> list = kyLaneMgylHistoryService.selectKyLaneMgylHistoryList(kyLaneMgylHistory);
        ExcelUtil<KyLaneMgylHistory> util = new ExcelUtil<KyLaneMgylHistory>(KyLaneMgylHistory.class);
        util.exportExcel(response, list, "描 杆（索）应力测点历史信息数据项说明数据");
    }

    /**
     * 获取描 杆（索）应力测点历史信息数据项说明详细信息
     */
    @PreAuthorize("@ss.hasPermi('pressure:mgylHistory:query')")
    @GetMapping(value = "/{kyLaneMgylRealId}")
    public AjaxResult getInfo(@PathVariable("kyLaneMgylRealId") String kyLaneMgylRealId)
    {
        return success(kyLaneMgylHistoryService.selectKyLaneMgylHistoryByKyLaneMgylRealId(kyLaneMgylRealId));
    }

    /**
     * 新增描 杆（索）应力测点历史信息数据项说明
     */
    @PreAuthorize("@ss.hasPermi('pressure:mgylHistory:add')")
    @Log(title = "描 杆（索）应力测点历史信息数据项说明", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KyLaneMgylHistory kyLaneMgylHistory)
    {
        return toAjax(kyLaneMgylHistoryService.insertKyLaneMgylHistory(kyLaneMgylHistory));
    }

    /**
     * 修改描 杆（索）应力测点历史信息数据项说明
     */
    @PreAuthorize("@ss.hasPermi('pressure:mgylHistory:edit')")
    @Log(title = "描 杆（索）应力测点历史信息数据项说明", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KyLaneMgylHistory kyLaneMgylHistory)
    {
        return toAjax(kyLaneMgylHistoryService.updateKyLaneMgylHistory(kyLaneMgylHistory));
    }

    /**
     * 删除描 杆（索）应力测点历史信息数据项说明
     */
    @PreAuthorize("@ss.hasPermi('pressure:mgylHistory:remove')")
    @Log(title = "描 杆（索）应力测点历史信息数据项说明", businessType = BusinessType.DELETE)
	@DeleteMapping("/{kyLaneMgylRealIds}")
    public AjaxResult remove(@PathVariable String[] kyLaneMgylRealIds)
    {
        return toAjax(kyLaneMgylHistoryService.deleteKyLaneMgylHistoryByKyLaneMgylRealIds(kyLaneMgylRealIds));
    }
}
